Attribute VB_Name = "basWinVersion"
Option Explicit

Public Type OSVERSIONINFO
  dwOSVersionInfoSize   As Long
  dwMajorVersion        As Long
  dwMinorVersion        As Long
  dwBuildNumber         As Long
  dwPlatformId          As Long
  szCSDVersion          As String * 128
End Type

Public Declare Function GetVersionExA Lib "kernel32" _
  (lpVersionInformation As OSVERSIONINFO) As Integer

Public Function GetWindowsVersion() As Integer
  ' Copied from MS KB article Q189249 and modified by bob mitch on 10/10/01
  ' Return values
  ' Unknown = 0
  ' Windows 95 = 1
  ' Windows 98 = 2
  ' Windows ME = 3
  ' Windows NT 3.51 = 4
  ' Windows NT 4.0 = 5
  ' Windows 2000 = 6
  ' Windows XP = 7
  Dim osinfo    As OSVERSIONINFO
  Dim retvalue  As Integer
  On Error GoTo ErrorHandler

  osinfo.dwOSVersionInfoSize = 148
  osinfo.szCSDVersion = Space$(128)
  retvalue = GetVersionExA(osinfo)

  With osinfo
    Select Case .dwPlatformId
      Case 1
        Select Case .dwMinorVersion
          Case 0
            GetWindowsVersion = 1 ' "Windows 95"
          Case 10
            GetWindowsVersion = 2 ' "Windows 98"
          Case 90
            GetWindowsVersion = 3 ' Windows ME
        End Select
      Case 2
        Select Case .dwMajorVersion
          Case 3
            GetWindowsVersion = 4  ' "Windows NT 3.51"
          Case 4
            GetWindowsVersion = 5  ' "Windows NT 4.0"
          Case 5
            If .dwBuildNumber = 2195 Then
              GetWindowsVersion = 6 ' "Windows 2000"
            Else
              GetWindowsVersion = 0 ' "Unknown"
            End If
        End Select
      Case Else
        GetWindowsVersion = 0 ' "Unknown"
    End Select
  End With
  
  Exit Function
  
ErrorHandler:
  GetWindowsVersion = 0
  
End Function

 

